﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using YEngineLib;

using Spyfall.Managers;

namespace Spyfall.States
{
    class AltitudeTimerClass
    {
        Texture2D texture;          //the scaler
        Texture2D texturePlayer;      //the image of the player / enemy
        Texture2D textureEnemy;
        Vector2 pos;
        Vector2 redPos;
        Vector2 bluePos;
        float amount;
        float speed;
        int lastSpdNum;

        float changeTimer;

        public bool powerUp;
        public bool powerDown;

        public void Initialize()
        {
            texture = YEngine.Game.Content.Load<Texture2D>("Graphics/HUD");          //SCALER
            texturePlayer = YEngine.Game.Content.Load<Texture2D>("Graphics/redline1");
            textureEnemy = YEngine.Game.Content.Load<Texture2D>("Graphics/blueline1");
            amount = YEngine.Graphics.ScreenViewport.Height;
            redPos.Y = 16;
            bluePos.Y = 40;
            powerUp = false;
            powerDown = false;
            changeTimer = 0.0f;
            lastSpdNum = LevelManager.GetInstance.SpeedUpNum;
        }

        public void Update(float fElapsedTime)
        {
            float fall = amount / LevelManager.GetInstance.Length * fElapsedTime;
            redPos.Y += fall;
            bluePos.Y += fall;

            if (lastSpdNum > LevelManager.GetInstance.SpeedUpNum)
            {
                lastSpdNum = LevelManager.GetInstance.SpeedUpNum;
                powerUp = true;
            }
            else if (lastSpdNum < LevelManager.GetInstance.SpeedUpNum)
            {
                lastSpdNum = LevelManager.GetInstance.SpeedUpNum;
                powerDown = true;
            }

            if (powerUp || powerDown)
            {
                changeTimer += fElapsedTime;

                if (changeTimer >= 0.5f)
                {
                    changeTimer = 0.0f;
                    powerUp = false;
                    powerDown = false;
                }

                if (powerUp)
                {
                    redPos.Y += fall * 2;
                }

                if (powerDown)
                {
                    redPos.Y -= fall * 2;
                }
            }

        }

        public void Draw()
        {
            pos.X = YEngine.Graphics.ScreenViewport.Width - texture.Width - 20;
            pos.Y = 0;
            YEngine.Graphics.SpriteBatch.Draw(texture, pos, Color.White);
            redPos.X = YEngine.Graphics.ScreenViewport.Width - texturePlayer.Width - 20;
            bluePos.X = YEngine.Graphics.ScreenViewport.Width - textureEnemy.Width - 20;

            YEngine.Graphics.SpriteBatch.Draw(texturePlayer, redPos, Color.White);
            YEngine.Graphics.SpriteBatch.Draw(textureEnemy, bluePos, Color.White);
        }

    }
}
